package com.wangbo.box.facade;

/**
 * 外观模式
 *
 * 一种通过为多个复杂的子系统提供一个一致的接口，而使这些子系统更加容易被访问的模式。
 */
public class FacadePattern {

    static class SubjectA{
        void showA(){
            System.out.println("subject A");
        }
    }
    static class SubjectB{
        void showB(){
            System.out.println("subject B");
        }
    }
    static class SubjectC{
        void showC(){
            System.out.println("subject C");
        }
    }

    static abstract class AbstractFacade{
       abstract void showAB();
       abstract void showBC();

    }

    static class FacadeAB extends AbstractFacade{
        SubjectA subjectA = new SubjectA();
        SubjectB subjectB = new SubjectB();

        @Override
        void showAB() {
            subjectA.showA();
            subjectB.showB();
        }

        @Override
        void showBC() {

        }
    }

    static class FacadeBC extends AbstractFacade{
        SubjectB subjectB = new SubjectB();
        SubjectC subjectC = new SubjectC();

        @Override
        void showAB() {
        }

        @Override
        void showBC() {
            subjectB.showB();
            subjectC.showC();
        }
    }

    public static void main(String[] args) {
        AbstractFacade facadeAB = new FacadeAB();
        facadeAB.showAB();
        AbstractFacade facadeBC = new FacadeBC();
        facadeBC.showBC();
    }
}
